<template>
	<view class="">
		<NavBar :title="navTitle" :isShowLeftBtn="true">
		</NavBar>
	</view>
	<view class="" v-if="isShowPage">
		<view class="" style="background: white;">
			<up-swiper :list="imgList" @change="e => currentNum = e.current" :autoplay="true"
				indicatorStyle="right: 20px" height="220">
				<template #indicator>
					<view class="indicator-num">
						<view class="">
							<text class=" f_24_0"
								style="color: #F5F5F5;">{{ currentNum + 1 }}/{{ imgList.length }}</text>
						</view>
					</view>
				</template>
			</up-swiper>
		</view>
		<view class="content" :style="{minHeight:contentHeight}">
			<view class="main">
				<view class="row1 m_b_20">
					<view class="m_b_22 flex_both">
						<view class="">
							<text class="f_30_0_b">
								{{storeDetail.shop_name}}
							</text>
						</view>
						<view class="cs_btn" @click="toCsXf" v-if="isShowCsBtn">
							<text class="f_24_f">
								到店消费
							</text>
						</view>
					</view>
					<view class="">
						<view class="flex" style="align-items: flex-start;">
							<view class="m_r_10">
								<text class="f_26_0_b">
									评分{{storeDetail.score}}
								</text>
							</view>
							<view class="m_t_4">
								<up-rate active-color="linear-gradient(to bottom, #FFFF59, #F9B900);"
									inactive-color="#b2b2b2" gutter="5" size="20" v-model="storeDetail.score"
									disabled></up-rate>
							</view>
						</view>
					</view>
					<view class="hr m_t_22 m_b_32">

					</view>
					<view class="">
						<view class="flex">
							<view class="m_r_12 m_b_6">
								<up-image :show-loading="true" src="/static/images/index/clock_icon.png" width="28rpx"
									height="28rpx"></up-image>
							</view>
							<view class="">
								<text class="f_24_0" style="color: #737272;">
									{{storeDetail.begin_hour}} - {{storeDetail.end_hour}}
								</text>
							</view>
							<view class="f_26_0 m_l_12 m_r_12 m_t_6" style="color: #737272;">
								<text>
									|
								</text>
							</view>
							<view class="">
								<view class="" v-if="storeDetail.is_stop">
									<text class="f_24_0" style="color: #737272;"
										v-if="storeDetail.is_yingye">
										暂停营业
									</text>
								</view>
								<view class="" v-else>
									<text class="f_24_0" style="color: #FE450C;"
										v-if="storeDetail.is_yingye">
										营业中
									</text>
									<text class="f_24_0" style="color: #FA7B27;" v-else>
										已打烊
									</text>
								</view>
							</view>
						</view>
					</view>
					<view class="hr m_t_28 m_b_28">

					</view>
					<view class="flex_both">
						<view class="">
							<view class="m_b_16 ">
								<text class="f_28_0_b">
									{{storeDetail.shop_name}}
								</text>
							</view>
							<view class="flex" style="align-items: flex-start;">
								<view class="m_r_6 m_t_2 m_l_6" style="width: 28rpx; height: 28rpx;flex-shrink: 0;">
									<up-image :show-loading="true" src="/static/images/index/position_icon.png"
										width="18rpx" height="24rpx"></up-image>
								</view>
								<view class="" style="width: 450rpx;">
									<text class="f_24_0" style="color: #737272;">
										{{storeDetail.address}}
									</text>

								</view>
							</view>
						</view>
						<view class="" @click="toOpenlocation(storeDetail)">
							<view class=""
								style="width: 76rpx;height: 76rpx; border-radius: 50%;display: flex;align-items: center;justify-content: center;background: #FBF1EC;">
								<view class="m_t_4">
									<up-icon name="/static/images/index/detail_dh.png" size="18"
										color="#F7480B"></up-icon>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="row2">
					<view class="row2_title flex_both">
						<view class="">
							<text class="f_30_0_b">
								评价（{{storeDetail.evaluateCount}}）
							</text>
						</view>
						<view class="" @click="toMoreEvaluate">
							<text class="f_24_9" style="color: #A9A8A8;">
								查看全部 >
							</text>
						</view>
					</view>
					<view class="row2_list">
						<view class="row2_item" v-for="(item,index) in evaluateList">
							<view class="flex m_b_20">
								<view class="m_r_14">
									<up-image :show-loading="true" :src="item.avatar" width="64rpx"
										height="64rpx" shape="circle"></up-image>
								</view>
								<view class="">
									<view class="">
										<text class="f_24_0 u-line-1" style="color: #181818;">
											{{item.nickname}}
										</text>
									</view>
									<view class="">
										<text class="f_22_0" style="color: #B1B1B2;">
											{{item.create_time}}
											<!-- 时间没有做判断 -->
										</text>
									</view>
								</view>
							</view>
							<view class="m_b_26">
								<text class="f_24_0" style="color: #4B4B4B;">
									{{item.evaluate_remark}}
								</text>
							</view>
							<view class="row2_item_img flex m_b_4">
								<view class="m_r_20 m_b_20" v-for="(item2,index2) in item.imgList" :key="index2">
									<up-image :show-loading="true" :src="item2" width="224rpx"
										height="204rpx"></up-image>
								</view>
							</view>
							<view class="row2_item_other_pj m_b_12" style="">
								<view class="row2_item_other_pj_item m_b_20" v-for="(item3,index3) in item.reviewList"
									:key="index3">
									<text class=" f_22_0" style="color: #7F7F7F;">
										{{item3.nickname}}：{{item3.content}}
									</text>
								</view>
							</view>
							<view class="flex" style="justify-content: flex-end;">
								<view class="flex m_r_28" @click="showPopup(index)">
									<view class="m_r_8 m_t_4">
										<up-icon name="/static/images/index/xx_icon.png" size="12"
											color="#C5C5C5"></up-icon>
									</view>
									<view class="">
										<text class="f_24_0" style="color: #181818;">
											评论
										</text>
									</view>
								</view>
								<view class="flex m_t_4">
									<view class="m_r_8">
										<view class="" v-if="item.is_like" @click="onDz(item,index,0)">
											<up-icon name="thumb-up" size="18" color="#F44816"></up-icon>
										</view>
										<view class="" v-else @click="onDz(item,index,1)">
											<up-icon name="thumb-up" size="18" color="#4D4D4D"></up-icon>
										</view>
									</view>
									<view class="f_24_0" style="color: #4D4D4D;">
										{{item.like_num}}
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="">
			<up-popup :show="popupShow" mode="bottom" round="10" :safeAreaInsetBottom="true">
				<view class="popup_box">
					<view class="popup_title m_b_46">
						<text class="f_30_0_b">
							评论
						</text>
					</view>
					<view class="popup_close" @click="onPopupClose">
						<up-icon name="close" color="#000000" size="17"></up-icon>
					</view>
					<view class="m_b_80">

						<up-textarea v-model="pjVal" placeholder="请输入" height="140"></up-textarea>
					</view>
					<view class="popup_btn" @click="onPopupOk">
						<view class="m_b_10">
							<text class="f_24_f">
								评论
							</text>
						</view>
					</view>
				</view>
			</up-popup>
		</view>
	</view>
</template>
<script setup lang="ts">
	import { ref, reactive, getCurrentInstance } from "vue";
	import { onLoad, onShow } from "@dcloudio/uni-app";
	import NavBar from "@/components/navbar.vue"
	const { proxy } = getCurrentInstance()
	const contentHeight = ref('100vh')
	const statusBarHeight = ref(88)
	const sId = ref(0)
	const isShowPage = ref(false)
	const navTitle = ref('详情')
	onLoad((e) => {
		uni.getSystemInfo({
			success: function (info) {
				statusBarHeight.value = (info.statusBarHeight + 44) * 2
				contentHeight.value = `calc(100vh - ${statusBarHeight.value + 80 + 342}rpx)`
			}
		});
		sId.value = e.id
		getConfig()
	})
	onShow(() => {
		getShopDetail()
		getEvaluate()
	})
	// 店铺详情
	const storeDetail = ref({})
	const getShopDetail = async () => {
		let res = await proxy.$http('index.getShopDetail', { shop_id: sId.value })
		let data = res.data
		navTitle.value = data.shop_name
		storeDetail.value = data
		if (data.shop_images) {
			imgList.value = data.shop_images.split(',')
		}
		isShowPage.value = true
	}
	// 评价列表 取前两条
	const evaluateList = ref([])
	const getEvaluate = async () => {
		let res = await proxy.$http('index.getEvaluate', { shop_id: sId.value })
		let data = res.data.data
		evaluateList.value = data.splice(0, 2)
		evaluateList.value.forEach(v => {
			if (v.evaluate_pic) {
				v.imgList = v.evaluate_pic.split(',')
			}
		})
	}

	// 点赞评价
	const onDz = async (e, index, type) => {
		let res = await proxy.$http('index.evaluateLike', { evaluate_id: e.evaluate_id, type: type })
		evaluateList.value[index].is_like = type
		if (type == 1) {
			evaluateList.value[index].like_num += 1
		} else {
			evaluateList.value[index].like_num -= 1
		}
	}
	// 更多评价
	const toMoreEvaluate = () => {
		proxy.$gloab.gotoPage(`/pages/index/evaluate?id=${sId.value}`)
	}

	const imgList = ref(['https://cdn.uviewui.com/uview/swiper/swiper3.png',
		'https://cdn.uviewui.com/uview/swiper/swiper2.png',
		'https://cdn.uviewui.com/uview/swiper/swiper1.png',])
	// 轮播
	const currentNum = ref(0)

	const toOpenlocation = (e) => {
		uni.openLocation({
			// 目标位置的经纬度
			latitude: parseFloat(e.lat),
			longitude: parseFloat(e.lng),
			// 目标位置的名称
			name: e.shop_name,
			// 目标位置的详细地址
			address: e.address,
			// 地图缩放比例
			scale: 18,
			// 调用成功时的回调函数
			success: function (res) {
				console.log('调用成功：', res)
			},
			// 调用失败时的回调函数
			fail: function (res) {
				console.log('调用失败：', res)
			},
			// 调用完成时的回调函数
			complete: function (res) {
				console.log('调用完成：', res)
			}
		})
	}
	// 评价
	const popupShow = ref(false)
	const activeIdx = ref(0)
	const pjVal = ref()
	const showPopup = (e) => {
		pjVal.value = ''
		activeIdx.value = e
		popupShow.value = true
	}
	const onPopupClose = () => {
		popupShow.value = false
	}
	const onPopupOk = () => {
		popupShow.value = false
		evaluateReview()
	}

	const evaluateReview = async () => {
		console.log();
		let res = await proxy.$http('index.evaluateReview', { evaluate_id: evaluateList.value[activeIdx.value].evaluate_id, content: pjVal.value })
		if (res.code == 1) {
			uni.$u.toast('已评论')
			setTimeout(() => {
				getEvaluate()
			}, 800)
		}
	}

	const isShowCsBtn = ref(false)
	const toCsXf = () => {
		uni.navigateTo({
			url: `/pages/index/scanCode?shopid=${storeDetail.value.shop_id}`
		})
	}
	const getConfig = async () => {
		let res = await proxy.$http('common.getConfig', { id: 24 })
		if (res.data == '1') {
			isShowCsBtn.value = true
		} else {
			isShowCsBtn.value = false
		}
	}
</script>
<style lang="scss" scoped>
	.indicator-num {
		text-align: center;
		width: 86rpx;
		height: 43rpx;
		padding-bottom: 4rpx;
		background: rgba(0, 0, 0, 0.5);
		border-radius: 22rpx;
		// opacity: 0.5;
	}

	.content {
		background: #F7F8FC;
		padding: 20rpx 0;
		padding-top: 0;
		padding-bottom: 64rpx;

		.row1 {
			padding: 30rpx 20rpx;
			padding-top: 34rpx;
			background: #ffffff;
			box-shadow: 2rpx 7rpx 5rpx 0rpx rgba(197, 197, 197, 0.29);
		}

		.row2 {
			background: #ffffff;

			.row2_title {
				padding: 32rpx 20rpx;
			}

			.row2_list {
				.row2_item {
					padding: 34rpx 20rpx;
					padding-bottom: 30rpx;
					border-top: 2rpx solid #F3F3F1;

					.row2_item_other_pj {
						.row2_item_other_pj_item {
							width: 631rpx;
							padding: 18rpx 24rpx;
							background: #F3F3F3;
							border-radius: 28rpx;
						}
					}
				}
			}
		}


	}

	::v-deep.uicon-star-fill {
		background: linear-gradient(to bottom, #FFFF59, #F9B900);
		/*设置渐变的方向从左到右 颜色从ff0000到ffff00*/
		-webkit-background-clip: text;
		/*将设置的背景颜色限制在文字中*/
		-webkit-text-fill-color: transparent;
		/*给文字设置成透明*/
	}

	.popup_box {
		padding: 46rpx;
		padding-top: 36rpx;
		background: #FFFFFF;
		border-radius: 10rpx;
		position: relative;

		.popup_title {
			text-align: center;
		}

		.popup_close {
			position: absolute;
			top: 18rpx;
			right: 18rpx;
			padding: 6rpx;
		}

		.popup_btn {
			margin: 0 auto;
			height: 83rpx;
			background: #F93F1A;
			border-radius: 10rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}

	::v-deep.u-textarea__field {
		font-size: 24rpx !important;
	}

	.cs_btn {
		width: 130rpx;
		height: 44rpx;
		border-radius: 22rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		background: #FD6C25;
	}
</style>